﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using UnityEngine;
using UnityEngine.UI;
using YummyGame.Framework;


public class Demo : MonoBehaviour
{
    public Text infoTxt;
    public Slider progress;
    public GameObject panel;
    public GameObject dialogPanel;
    public Text updateTxt;
    public Text errorTxt;
    public Button okBtn;
    public Button cancelBtn;

    SkillOwner comp1;
    SkillOwner comp2;
    private void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
        //try
        //{
        //    AssetInitializeListener listener = new AssetInitializeListener();
        //    listener.ProgressInfo = updateInfo;
        //    listener.InitializeCallback = () =>
        //    {
        //        DebugView.Log("callback");
        //        //AssetLoader loader = new AssetLoader();
        //        //loader.LoadAssetAsync<GameObject>("Panel", (go) =>
        //        //{
        //        //    GameObject g = GameObject.Instantiate(go);
        //        //    g.transform.SetParent(this.gameObject.transform, false);
        //        //});
        //        SceneManager.Instance.LoadScene("Scene/test_scene")
        //        .OnTaskFinish((_) => Debug.Log("on sceneLoaded"));
        //        panel.SetActive(false);
        //        dialogPanel.SetActive(false);
        //        AssetManager.Instance.LoadLuaFile("main","start");
        //    };
        //    listener.ErrorCallback = (err) => errorTxt.text = err;
        //    listener.ConfirmCallback = (length, action, cancel) =>
        //    {
        //        dialogPanel.SetActive(true);
        //        updateTxt.text = "检测到需要更新:" + length / 1024 + "k,是否更新?";
        //        okBtn.onClick.AddListener(() => { action(); dialogPanel.SetActive(false); });
        //        cancelBtn.onClick.AddListener(() => { cancel(); dialogPanel.SetActive(false); });
        //    };
        //    AssetManager.Instance.Initalize(listener);
        //}catch(Exception e)
        //{
        //    errorTxt.text = e.Message + "\n" + e.StackTrace;
        //}

        
    }

    void updateInfo(string msg,float p)
    {
        infoTxt.text = msg;
        progress.value = p;
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        //if (Input.GetKeyDown(KeyCode.A))
        //{
        //    SceneManager.Instance.LoadScene("Scene/test_scene");
        //}
        //else if (Input.GetKeyDown(KeyCode.B))
        //{
        //    SceneManager.Instance.LoadScene("Scene/test");
        //}
        
    }

}

